﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>注册</title>
    <link href="ViewV5/web/css/css.css" rel="stylesheet" />
    <link href="ViewV5/web/css/default.css" rel="stylesheet" />
    <style>
        a {
        cursor:pointer;
        }
    </style>
</head>
<body >

   
    <div class="main_content">
        <form>
            <div class="form_content">
                <div class="title">注册新帐号</div>
                <div class="bd">
                    <div class="input_default">
                        <em class="intro">企&nbsp;业&nbsp;名&nbsp;称：</em>
                        <input name="company" id="company" type="text" class="J_form_input" value="" placeholder="建议采用公司全名"/>
                        <b class="input_question"></b>
                        <div class="que_cont">
                            <em></em>
                            <p><b>建议采用公司全名</b></p>
                        </div>
                        <em class="validation-icon"></em>
                        <p class="tips"></p>
                    </div> 
                    <div class="input_default">
                        <em class="intro">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码：</em>

                        <input type="password" name="password" id="password" class="J_form_input" value=""  autocomplete="off"/>
                        <em class="validation-icon"></em>
                        <p class="tips"></p>
                    </div>
                     <div class="input_default">
                        <em class="intro">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</em>

                        <input type="text" name="xm" id="xm" class="J_form_input" value="" />
                        <em class="validation-icon"></em>
                        <p class="tips"></p>
                    </div>
                    <!--<div class="input_default">
                        <em class="intro">确&nbsp;认&nbsp;密&nbsp;码：</em>
                        <input name="password1" id="password1" type="password" class="J_form_input" value="" />
                        <em class="validation-icon"></em>
                        <p class="tips"></p>
                    </div>-->
                    <div class="input_default">
                        <em class="intro">手&nbsp;&nbsp;&nbsp;机&nbsp;&nbsp;&nbsp;号：</em>
                        <b class="input_question"></b>
                        <div class="que_cont">
                            <em></em>
                            <p><b>手机号将作为管理员的登录账号，一个手机号只能注册一个企业哦</b></p>
                        </div>
                        <input name="Phone" id="Phone" type="text" class="J_form_input" value="" placeholder="手机号" />
                        <em class="validation-icon"></em>
                        <p class="tips"></p>
                    </div>
                    <div class="input_default input_spec">
                        <em class="intro">验&nbsp;&nbsp;&nbsp;证&nbsp;&nbsp;&nbsp;码：</em>
                        <input name="YZM" id="YZM" type="text" class="J_form_input" value="" />
                        <p class="tips"></p>
                        <button class="yzm" onclick="sendYZM();">发送验证码</button>
                    </div>
                </div>
                <div class="user_xy" style="text-align:center; color:#999">
                    <label><input type="checkbox" value="复选框" checked="checked" />我已阅读并接受<a href="agreement.html" target="_blank" style="color:#53B8A6;">《用户注册协议》</a></label>
                    <p class="tips" style="color: #ef777d;"></p>
                </div>
                <div class="btnbox" style="margin-top:25px;">
                    <button type="button" class="J_form_button J_form_button_l" onclick="SaveForm(this)">立即注册</button>
                </div>
            </div>
        </form>
    </div>
    <div class="main_content" style="display:none">
        <div class="form_content">
            <div class="ts">
                <img src="/web/images/yes.png" />
                恭喜您，注册成功！
            </div>
            <div class="ts_cg">
                <p>
                    <span>企业名称：</span>
                    <em id="lblCompany"> </em>
                </p> 
                <p>
                    <span>管理员手机：</span>
                    <em id="lblMobile"></em>
                </p>
            </div>
            <div class="btnbox">
                <a href="/Login.html" id="loginbtn" target="_blank" class="J_form_button J_form_button_l">马上登陆</a>
            </div>
        </div>
    </div>
    <script src="ViewV5/web/js/jquery-1.9.1.min.js"></script>
    <script src="/ViewV5/JS/jquery.md5.js"></script>
    <script src="/ViewV5/JS/SZHLCommon.js"></script>
    <script>
        var msg = "";
        var Times = 60;
        var intervalId;
        function TimeDown() {
            Times = Times - 1;
            if (Times == 0) {
                $(".yzm").text("重新获取");
                $(".yzm").attr("disabled", false);
                clearInterval(intervalId);
            }
            else {
                $(".yzm").text(Times + "秒后重新获取");
            }
        }
        //获取验证码
        function sendYZM() {
            $(".yzm").attr("disabled", true);
            if (Times == 60) {
                msg = "";
                if (!$("#Phone").val() || !(/^1[3|4|5|8|7][0-9]\d{8}$/).test($("#Phone").val())) {
                    $("#Phone").parent().addClass("input_error");
                    msg = "请输入正确的手机号";
                    $("#Phone").parent().find(".tips").text(msg);
                }
                $.ajaxSettings.async = false;
                $.getJSON('/API/VIEWAPI.ashx?Action=Commanage_CHECKREGISTERPHONE', { P1: $("#Phone").val() }, function (resultData) {
                    if (resultData.ErrorMsg != "") {
                        $("#Phone").parent().addClass("input_error");
                        msg = resultData.ErrorMsg;
                        $("#Phone").parent().find(".tips").text(msg);
                    }
                })
                if (!msg) {
                    Times = 60;
                    $(".yzm").text(Times + "秒后重新获取");
                    intervalId = setInterval(TimeDown, 1000);
                    $.ajax({
                        url: "/API/VIEWAPI.ashx?Action=Commanage_SENDCHKMSG&r=" + Math.random(),
                        type: "POST",
                        data: { P1: $("#Phone").val() },
                        async: false,
                        success: function (result) {
                            var jsonresult = $.parseJSON(result);
                            if (jsonresult.ErrorMsg == "") {
                                var exp = new Date();
                                exp.setTime(exp.getTime() + 30 * 60 * 1000);
                                document.cookie = "chkcode=" + escape(jsonresult.Result) + ";expires=" + exp.toGMTString() + ";path=/";
                                document.cookie = "chkphone=" + escape($("#Phone").val()) + ";expires=" + exp.toGMTString() + ";path=/";
                            } else {
                                $("#YZM").parent().find(".tips").text(msg);
                            }
                        },
                        error: function (xhr) {
                            $("#YZM").parent().find(".tips").text(msg);
                        }
                    });
                }
            }
        }
        $(".input_default .J_form_input").blur(function () {
            CheckData(this);
        })
        function CheckForm() {
            //提示 input_focus  通过 input_pass 错误 input_error
            $(".input_default .J_form_input").each(function () {
                CheckData(this);
            })

        }
        function SaveForm(dom) {
            $(dom).text("正在提交，请稍等");
            $(dom).attr("disabled", true);
            CheckForm();
            if ($(".input_focus").length + $(".input_error").length > 0) {
                $(dom).text("立即注册");
                $(dom).attr("disabled", false);
                return false;
            }

            var inputData = { "QYName": $("#company").val(), "UserPass": $("#password").val(), "mobphone": $("#Phone").val(), "xm": $("#xm").val() };
            $.post("/API/VIEWAPI.ashx?Action=Commanage_REGISTERNEW&r=" + Math.random(), { "P1": JSON.stringify(inputData), ID: ComFunJS.getQueryString("ID") }, function (data) {
                var data = $.parseJSON(data);
                if (data.ErrorMsg == "") {
                    $("#lblCompany").text(inputData.QYName);  
                    $("#loginbtn").attr("href", "login.html");
                    $("#lblMobile").text(inputData.mobphone);
                    $(".main_content").eq(0).hide();
                    $(".main_content").eq(1).show();
                }
                else {
                    $(dom).text("立即注册");
                    $(dom).attr("disabled", false);
                }
            })

        }
        function CheckData(dom) {
            msg = "";
            $(dom).parent().removeClass("input_focus").removeClass("input_pass").removeClass("input_error")
            if (!$(dom).val()) {
                $(dom).parent().addClass("input_focus");
                var tipsContent = $(dom).parent().find(".intro").text();
                msg = "请输入" + $.trim(tipsContent.substring(0, tipsContent.length - 1)).replace(/\s+/g, "");
            } 
            if (!msg && $(dom).attr("id") == "company") {
                //验证企业名称是否存在
                $.ajax({
                    url: "/API/VIEWAPI.ashx?Action=Commanage_YZQYMC&r=" + Math.random(),
                    type: "POST",
                    data: { P1: $('#company').val().toUpperCase() },
                    async: false,
                    success: function (result) {
                        var jsonresult = $.parseJSON(result);
                        if (jsonresult.ErrorMsg != "") {
                            msg = jsonresult.ErrorMsg;
                            $(dom).parent().addClass("input_error");
                        }
                    },
                    error: function (xhr) {
                        msg = "企业名称已存在";
                        $(dom).parent().addClass("input_error");
                    }
                });
            }
        
            var strRegex = /^(?=.*[a-zA-Z]+)(?=.*[0-9]+)[a-zA-Z0-9]+$/;
            if (!msg && $(dom).attr("id") == "password" && (!strRegex.test($(dom).val()) || $.trim($(dom).val()).length < 6 || $.trim($(dom).val()).length > 16)) {
                $(dom).parent().addClass("input_error");
                msg = "密码必须为6-16位长度,建议用英文和数字的组合";
            }
            if (!msg && $(dom).attr("id") == "Phone") {
                if (!(/^1[3|4|5|8|7][0-9]\d{8}$/).test($(dom).val())) {
                    $(dom).parent().addClass("input_error");
                    msg = "请输入正确的手机号";
                }
                if (!msg) {
                    $.ajaxSettings.async = false;
                    $.getJSON('/API/VIEWAPI.ashx?Action=Commanage_CHECKREGISTERPHONE', { P1: $(dom).val() }, function (resultData) {
                        if (resultData.ErrorMsg != "") {
                            $(dom).parent().addClass("input_error");
                            msg = resultData.ErrorMsg;
                        }
                    })
                }

            }
            if (!msg && $(dom).attr("id") == "YZM") {
                if ($(dom).val().length != 4) {
                    $(dom).parent().addClass("input_error");
                    msg = "请输入四位的验证码";
                } else {

                    var arr, reg = new RegExp("(^| )chkcode=([^;]*)(;|$)");
                    if (arr = document.cookie.match(reg)) {
                        var ckc = unescape(arr[2]);
                        if ($.md5($(dom).val()).toUpperCase() == ckc) {
                            var arr1, reg1 = new RegExp("(^| )chkphone=([^;]*)(;|$)");
                            if (arr1 = document.cookie.match(reg1)) {
                                var ckp = unescape(arr1[2]);
                                if (ckp != $("#Phone").val()) {
                                    $(dom).parent().addClass("input_error");
                                    msg = "验证码和手机号不匹配";
                                }
                            }
                            else {
                                $(dom).parent().addClass("input_error");
                                msg = "输入的验证码错误";
                            }
                        }
                        else {
                            $(dom).parent().addClass("input_error");
                            msg = "没有获取验证码或已过期";
                        }
                    } else {
                        $(dom).parent().addClass("input_error");
                        msg = "请输入正确的验证码";
                    }
                }
            }
            if (!msg) {
                $(dom).parent().addClass("input_pass");
            }
            $(dom).parent().find(".tips").text(msg);

        }
        //帮助信息
        $(".input_question").hover(function () {
            $(this).next(".que_cont").toggle();
        });
    </script>
</body>
</html>
